import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
import '../../provider/cart.dart';
import '../../provider/details_info.dart';
import '../../provider/current_index.dart';

class DetailsBottom extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      width: ScreenUtil().setWidth(750),
      height: ScreenUtil().setHeight(80),
      color: Colors.white,
      child: Consumer3<CartProvider, DetaiInfoProvider, CurrentIndexProvider>(
        builder: (context, CartProvider cartProvider, DetaiInfoProvider detailProvider, CurrentIndexProvider currentIndexProvider, child) {
          return Row(
            children: <Widget>[
              InkWell(
                onTap: (){
                  currentIndexProvider.changIndex(2);
                  Navigator.pop(context);
                },
                child: Stack(
                  children: <Widget>[
                    Container(
                      width: ScreenUtil().setWidth(110),
                      height: ScreenUtil().setHeight(80),
                      alignment: Alignment.center,
                      child: Icon(
                        Icons.shopping_cart,
                        size: 35,
                        color: Colors.red,
                      ),
                    ),
                    Positioned(
                      top: 0,
                      right: 5.0,
                      child: Container(
                        width: ScreenUtil().setWidth(40),
                        height: ScreenUtil().setHeight(40),
                        decoration: BoxDecoration(
                          color: Colors.red,
                          borderRadius: BorderRadius.circular(ScreenUtil().setWidth(20)),
                          border: Border.all(width: 1, color: Colors.white)
                        ),
                        alignment: Alignment.center,
                        child: Text(
                          '${cartProvider.allGoodsCount}',
                          style: TextStyle(
                            fontSize: ScreenUtil().setSp(22),
                            color: Colors.white
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              InkWell(
                onTap: (){
                  var goodsInfo = detailProvider.goodsInfo.data.goodInfo;
                  var goodsId = goodsInfo.goodsId;
                  var goodsName = goodsInfo.goodsName;
                  var count = 1;
                  var price = goodsInfo.presentPrice;
                  var images = goodsInfo.image1;
                  cartProvider.save(goodsId, goodsName, count, price, images);
                },
                child: _button(Colors.green, '加入购物车'),
              ),
              InkWell(
                onTap: (){
                  cartProvider.remove();
                },
                child: _button(Colors.red, '马上购买'),
              ),
            ],
          );
        },
      ),
    );
  }

  // 按钮
  Widget _button(Color color, String content) {
    return Container(
      width: ScreenUtil().setWidth(320),
      height: ScreenUtil().setHeight(80),
      color: color,
      alignment: Alignment.center,
      child: Text(
        content,
        style: TextStyle(
          fontSize: ScreenUtil().setSp(28),
          color: Colors.white
        ),
      ),
    );
  }
}